home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / SpellCompositor / SpellEditFrame.java < prev    next >
Encoding:
Java Source  |  2001-06-23  |  14.4 KB  |  472 lines

  1. /*
  2.     ArcanaApp.SpellEditFrame
  3.         - an interface by which to edit the spell records of the spellbook.
  4.     
  5.     Written by Scott C. Ziegler for use with Simulcra™.
  6.     
  7.     vers. history:
  8.         07.08.00 - achieved syntactically correct version.
  9.         09.19.00 - decided to overhaul project using layout managers
  10.         10.25.00 - began project to make a functional spell book app
  11.         12.12.00 - finalized first version of API for GUI (menus remain),
  12.                     added area of effect field and label
  13.     
  14.     Work Needed:
  15.         - finish initMenus()
  16.         - complete the ComboBox implementation details !!!IMPORTANT!!!
  17.         - link events with underlying code libs (i.e. SpellRecord, SpellFiling, etc.)
  18.         - add JDialog error handlers.
  19.         - add JDialog warnings to delete and clear record buttons.
  20.     
  21.     Work Completed:
  22.         - added menu items and categories
  23.         - added event architecture to buttons etc.
  24.         - made AreaOfEffect textfield and label
  25.  
  26. */
  27.  
  28. /*
  29. This file and its intellectual contents are considered property of the creator and are to be treated as such with respect to use in other applications.  Any use of this software for any purpose whatsoever must have explicit permission from the author of the file.  This code is part of an ongoing development process for future possible products, and so is considered private property.
  30. Do not use without permission.  Author: Scott C. Ziegler <Aslan@Narnia.net>
  31. */
  32.  
  33. package Thoth;
  34.  
  35. import java.awt.*;
  36. import java.awt.event.*;
  37. import java.util.*;
  38.  
  39. import javax.swing.*;
  40. import javax.swing.border.*;
  41. import javax.swing.event.*;
  42.  
  43. public class SpellEditFrame extends JFrame {
  44.     
  45.     Insets objectInsets = new Insets(2,2,2,2);
  46.     
  47.     // Panels
  48.     
  49.     JPanel         buttonPanel;
  50.     JPanel        recordPanel;
  51.     
  52.     // Menus
  53.     
  54.     JMenuBar            menuBar;
  55.     JMenu                fileMenu;
  56.         JMenuItem            aboutBoxMenuItem;
  57.         JMenuItem            quitMenuItem;
  58.     JMenu                editMenu;
  59.         JMenuItem            undoMenuItem;
  60.         JMenuItem            cutMenuItem;
  61.         JMenuItem            copyMenuItem;
  62.         JMenuItem            pasteMenuItem;
  63.     JMenu                optionsMenu;
  64.         JMenuItem             optionsMenuItem;
  65.     JMenu                someMenu;
  66.         JMenuItem            someMenuItem;
  67.     
  68.     // Buttons
  69.     
  70.     JButton        backButton;
  71.     JButton        nextButton;
  72.     JButton        prevLvlButton;
  73.     JButton        fwdLvlButton;
  74.     JButton        viewButton;
  75.     JButton        saveButton;
  76.     JButton        clearButton;
  77.     JButton        newButton;
  78.     
  79.     // Labels
  80.     
  81.     JLabel        nameLabel;
  82.     JLabel        levelLabel;
  83.     JLabel        schoolLabel;
  84.     JLabel        componentsLabel;
  85.     JLabel        rangeLabel;
  86.     JLabel        durationLabel;
  87.     JLabel        castingTimeLabel;
  88.     JLabel        areaOfEffectLabel;
  89.     JLabel        savingThrowLabel;
  90.     JLabel        descriptionLabel;
  91.     
  92.     // Text Fields
  93.     
  94.     JTextField        nameTextField;
  95.     JTextField        levelTextField;
  96.     JComboBox        schoolComboBox;
  97.     JComboBox        componentsComboBox;
  98.     JTextField        rangeTextField;
  99.     JTextField        durationTextField;
  100.     JTextField        castingTimeTextField;
  101.     JTextField        areaOfEffectTextField;
  102.     JTextField        savingThrowTextField;
  103.     
  104.     JScrollPane        descriptionScrollPane;
  105.     JTextArea        descriptionTextArea;
  106.     
  107.     ActionListener    navigationListener;
  108.     ActionListener    manipulationListener;
  109.     ActionListener    aboutListener;
  110.     ActionListener    quitListener;
  111.     
  112.     // Constructors
  113.     
  114.     public SpellEditFrame() {
  115.         
  116.         super("Arcana Spell Edit");
  117.         
  118.         initMenus();
  119.         initButtons();
  120.         initRecordPanel();
  121.         initDescriptionArea();
  122.         
  123.         setJMenuBar(menuBar);
  124.         Container progFrameContentPane = getContentPane();
  125.         progFrameContentPane.add(buttonPanel, BorderLayout.NORTH);
  126.         progFrameContentPane.add(recordPanel, BorderLayout.CENTER);
  127.         progFrameContentPane.add(descriptionScrollPane, BorderLayout.SOUTH);
  128.         
  129.         setSize(new Dimension(500,600));
  130.         //setVisible(true);
  131.         
  132.         addWindowListener(new java.awt.event.WindowAdapter() {
  133.             public void windowClosing(java.awt.event.WindowEvent e) {
  134.                 thisWindowClosing(e);
  135.                 }
  136.             });
  137.         }
  138.     
  139.     // Selectors
  140.     
  141.     public Arcana.SpellRecord getSpell() {
  142.         Arcana.SpellRecord spell = new Arcana.SpellRecord();
  143.         spell.setLevel(Integer.parseInt(levelTextField.getText()));
  144.         spell.setName(nameTextField.getText());
  145.         spell.setSchool((String)schoolComboBox.getSelectedItem());
  146.         spell.setRange(rangeTextField.getText());
  147.         spell.setComponentsByString((String)componentsComboBox.getSelectedItem());
  148.         spell.setDuration(durationTextField.getText());
  149.         spell.setCastingTime(castingTimeTextField.getText());
  150.         spell.setAreaOfEffect(areaOfEffectTextField.getText());
  151.         spell.setSavingThrow(savingThrowTextField.getText());
  152.         spell.setEffect(new Arcana.SpellDescription(new String(descriptionTextArea.getText())));
  153.         return spell;
  154.         }
  155.     
  156.     // Mutators
  157.         
  158.     public void setNavigationListener(ActionListener nl) {
  159.         backButton.removeActionListener(navigationListener);
  160.         backButton.addActionListener(nl);
  161.         nextButton.removeActionListener(navigationListener);
  162.         nextButton.addActionListener(nl);
  163.         fwdLvlButton.removeActionListener(navigationListener);
  164.         fwdLvlButton.addActionListener(nl);
  165.         prevLvlButton.removeActionListener(navigationListener);
  166.         prevLvlButton.addActionListener(nl);
  167.         }
  168.         
  169.     public void setManipulationListener(ActionListener ml) {
  170.         viewButton.removeActionListener(manipulationListener);
  171.         viewButton.addActionListener(ml);
  172.         saveButton.removeActionListener(manipulationListener);
  173.         saveButton.addActionListener(ml);
  174.         clearButton.removeActionListener(manipulationListener);
  175.         clearButton.addActionListener(ml);
  176.         newButton.removeActionListener(manipulationListener);
  177.         newButton.addActionListener(ml);
  178.         }
  179.         
  180.     public void setAboutListener(ActionListener al) {
  181.         aboutBoxMenuItem.removeActionListener(aboutListener);
  182.         aboutBoxMenuItem.addActionListener(al);
  183.         }
  184.         
  185.     public void setQuitListener(ActionListener ql) {
  186.         quitMenuItem.removeActionListener(quitListener);
  187.         quitMenuItem.addActionListener(ql);
  188.         }
  189.         
  190.     // Methods
  191.     
  192.     private void initMenus() {
  193.         menuBar = new JMenuBar();
  194.         menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
  195.  
  196.         fileMenu = new JMenu("File");
  197.         fileMenu.setMnemonic('F');
  198.         aboutBoxMenuItem = new JMenuItem("About…");
  199.         fileMenu.add(aboutBoxMenuItem);
  200.         aboutListener = new ActionListener() {
  201.             public void actionPerformed(ActionEvent ae) {
  202.                 
  203.                 }
  204.             };
  205.         aboutBoxMenuItem.addActionListener(aboutListener);
  206.         quitMenuItem = new JMenuItem("Quit");
  207.         fileMenu.add(quitMenuItem);
  208.         quitListener = new ActionListener() {
  209.             public void actionPerformed(ActionEvent ae) {
  210.                 System.exit(0);
  211.                 }
  212.             };
  213.         quitMenuItem.addActionListener(quitListener);
  214.         editMenu = new JMenu("Edit");
  215.         undoMenuItem = new JMenuItem("Undo");
  216.         editMenu.add(undoMenuItem);
  217.         cutMenuItem = new JMenuItem("Cut");
  218.         editMenu.add(cutMenuItem);
  219.         copyMenuItem = new JMenuItem("Copy");
  220.         editMenu.add(copyMenuItem);
  221.         pasteMenuItem = new JMenuItem("Paste");
  222.         editMenu.add(pasteMenuItem);
  223.         optionsMenu = new JMenu("Options");
  224.         optionsMenuItem = new JMenuItem("Options…");
  225.         optionsMenu.add(optionsMenuItem);
  226.         someMenu = new JMenu("Something");
  227.         someMenuItem = new JMenuItem("Something…");
  228.         menuBar.add(fileMenu);
  229.         menuBar.add(editMenu);
  230.         menuBar.add(optionsMenu);
  231.         menuBar.add(someMenu);
  232.         }
  233.         
  234.     private void initButtons() {
  235.         navigationListener = new ActionListener() {
  236.             public void actionPerformed(ActionEvent ae) {
  237.                 String com = ae.getActionCommand();
  238.                      if (com.compareTo("Back") == 0) {
  239.                          
  240.                         }
  241.                 else if (com.compareTo("Next") == 0) {
  242.                     
  243.                     }
  244.                 else if (com.compareTo("PrevLvl") == 0) {
  245.                     
  246.                     }
  247.                 else if (com.compareTo("FwdLvl") == 0) {
  248.                 
  249.                     }
  250.                 }
  251.             };
  252.         manipulationListener = new ActionListener() {
  253.             public void actionPerformed(ActionEvent ae) {
  254.                 String com = ae.getActionCommand();
  255.                      if (com.compareTo("View") == 0) {
  256.                          
  257.                         }
  258.                 else if (com.compareTo("Save") == 0) {
  259.                     
  260.                     }
  261.                 else if (com.compareTo("Clear") == 0) {
  262.                     
  263.                     }
  264.                 else if (com.compareTo("New") == 0) {
  265.                 
  266.                     }
  267.                 }
  268.             };
  269.         backButton = new JButton("Back");
  270.         backButton.addActionListener(navigationListener);
  271.         nextButton = new JButton("Next");
  272.         nextButton.addActionListener(navigationListener);
  273.         prevLvlButton = new JButton("PrevLvl");
  274.         prevLvlButton.addActionListener(navigationListener);
  275.         fwdLvlButton = new JButton("FwdLvl");
  276.         fwdLvlButton.addActionListener(navigationListener);
  277.         viewButton = new JButton("View");
  278.         viewButton.addActionListener(manipulationListener);
  279.         saveButton = new JButton("Save");
  280.         saveButton.addActionListener(manipulationListener);
  281.         clearButton = new JButton("Clear");
  282.         clearButton.addActionListener(manipulationListener);
  283.         newButton = new JButton("New");
  284.         newButton.addActionListener(manipulationListener);
  285.         
  286.         buttonPanel = new JPanel();
  287.         buttonPanel.setLayout(new GridLayout(2,4,5,5));
  288.         buttonPanel.add(backButton);
  289.         buttonPanel.add(nextButton);
  290.         buttonPanel.add(viewButton);
  291.         buttonPanel.add(clearButton);
  292.         buttonPanel.add(prevLvlButton);
  293.         buttonPanel.add(fwdLvlButton);
  294.         buttonPanel.add(saveButton);
  295.         buttonPanel.add(newButton);
  296.         }
  297.     
  298.     private void initRecordPanel() {
  299.         recordPanel = new JPanel();
  300.         recordPanel.setLayout(new GridBagLayout());
  301.         GridBagConstraints c = new GridBagConstraints();
  302.         
  303.         nameLabel = new JLabel("Name:");
  304.         nameTextField = new JTextField();
  305.         levelLabel = new JLabel("Level:");
  306.         levelTextField = new JTextField();
  307.         schoolLabel = new JLabel("School:");
  308.         schoolComboBox = new JComboBox();
  309.         componentsLabel = new JLabel("Components:");
  310.         componentsComboBox = new JComboBox();
  311.         rangeLabel = new JLabel("Range:");
  312.         rangeTextField = new JTextField();
  313.         durationLabel = new JLabel("Duration");
  314.         durationTextField = new JTextField();
  315.         castingTimeLabel = new JLabel("Casting Time:");
  316.         castingTimeTextField = new JTextField();
  317.         areaOfEffectLabel = new JLabel("Area Of Effect");
  318.         areaOfEffectTextField = new JTextField();
  319.         savingThrowLabel = new JLabel("Saving Throw:");
  320.         savingThrowTextField = new JTextField();
  321.         descriptionLabel = new JLabel("Description:");
  322.         
  323.         schoolComboBox.addItem("Abjuration");
  324.         schoolComboBox.addItem("Alteration");
  325.         schoolComboBox.addItem("Conjuration/Summoning");
  326.         schoolComboBox.addItem("Enchantment/Charm");
  327.         schoolComboBox.addItem("Illusion/Phantasm");
  328.         schoolComboBox.addItem("Invocation/Evocation");
  329.         schoolComboBox.addItem("Divination");
  330.         schoolComboBox.addItem("Necromancy");
  331.         schoolComboBox.addItem("Wild Magic");
  332.         
  333.         componentsComboBox.addItem("Verbal");
  334.         componentsComboBox.addItem("Somantic");
  335.         componentsComboBox.addItem("Material");
  336.         componentsComboBox.addItem("Verbal, Somantic");
  337.         componentsComboBox.addItem("Somantic, Material");
  338.         componentsComboBox.addItem("Verbal, Material");
  339.         componentsComboBox.addItem("Verbal, Somantic, Material");
  340.         
  341.         setGBConstraints(c,0,0,true);
  342.         recordPanel.add(nameLabel, c);
  343.         setGBConstraints(c,1,0,false);
  344.         recordPanel.add(nameTextField, c);
  345.         
  346.         setGBConstraints(c,0,1,true);
  347.         recordPanel.add(levelLabel, c);
  348.         setGBConstraints(c,1,1,false);
  349.         recordPanel.add(levelTextField, c);
  350.         
  351.         setGBConstraints(c,0,2,true);
  352.         recordPanel.add(schoolLabel, c);
  353.         setGBConstraints(c,1,2,false);
  354.         recordPanel.add(schoolComboBox, c);
  355.         
  356.         setGBConstraints(c,0,3,true);
  357.         recordPanel.add(componentsLabel, c);
  358.         setGBConstraints(c,1,3,false);
  359.         recordPanel.add(componentsComboBox, c);
  360.         
  361.         setGBConstraints(c,0,4,true);
  362.         recordPanel.add(rangeLabel, c);
  363.         setGBConstraints(c,1,4,false);
  364.         recordPanel.add(rangeTextField, c);
  365.         
  366.         setGBConstraints(c,0,5,true);
  367.         recordPanel.add(durationLabel, c);
  368.         setGBConstraints(c,1,5,false);
  369.         recordPanel.add(durationTextField, c);
  370.         
  371.         setGBConstraints(c,0,6,true);
  372.         recordPanel.add(castingTimeLabel, c);
  373.         setGBConstraints(c,1,6,false);
  374.         recordPanel.add(castingTimeTextField, c);
  375.         
  376.         setGBConstraints(c,0,7,true);
  377.         recordPanel.add(areaOfEffectLabel, c);
  378.         setGBConstraints(c,1,7,false);
  379.         recordPanel.add(areaOfEffectTextField, c);
  380.         
  381.         setGBConstraints(c,0,8,true);
  382.         recordPanel.add(savingThrowLabel, c);
  383.         setGBConstraints(c,1,8,false);
  384.         recordPanel.add(savingThrowTextField, c);
  385.         
  386.         setGBConstraints(c,0,9,true);
  387.         recordPanel.add(descriptionLabel, c);
  388.         }
  389.         
  390.     private void setGBConstraints(GridBagConstraints gbc, int x, int y, boolean lbl_field) {
  391.         gbc.gridx = x; gbc.gridy = y; gbc.gridheight = 1; gbc.gridwidth = 1;
  392.         gbc.weightx = (lbl_field?20:80); gbc.weighty = 11;
  393.         gbc.fill = (lbl_field?GridBagConstraints.NONE:GridBagConstraints.BOTH);
  394.         gbc.anchor = (lbl_field?GridBagConstraints.WEST:GridBagConstraints.CENTER);
  395.         gbc.insets = objectInsets;
  396.         }
  397.         
  398.     private void initDescriptionArea() {
  399.         descriptionScrollPane = new JScrollPane();
  400.         descriptionTextArea = new JTextArea();
  401.         descriptionTextArea.setRows(15);
  402.         descriptionTextArea.setLineWrap(true);
  403.         descriptionTextArea.setWrapStyleWord(true);
  404.         descriptionScrollPane.getViewport().add(descriptionTextArea);
  405.         // sizing?
  406.         }
  407.     
  408.     // Close the window when the close box is clicked
  409.     void thisWindowClosing(java.awt.event.WindowEvent e) {
  410.         setVisible(false);
  411.         clearFields();
  412.         // dispose();
  413.         // System.exit(0);
  414.         }
  415.         
  416.     public void clearFields() {
  417.         nameTextField.setText("");
  418.         levelTextField.setText("");
  419.         rangeTextField.setText("");
  420.         durationTextField.setText("");
  421.         castingTimeTextField.setText("");
  422.         areaOfEffectTextField.setText("");
  423.         savingThrowTextField.setText("");
  424.         descriptionTextArea.setText("");
  425.         schoolComboBox.setSelectedIndex(0);
  426.         componentsComboBox.setSelectedIndex(0);
  427.         }
  428.     
  429.     
  430.     // need to make selection criteria less rigid.  "contains?" predicates perhaps?
  431.     public void displaySpell(Arcana.SpellRecord spell) {
  432.         nameTextField.setText(spell.getName());
  433.         levelTextField.setText("" + spell.getLevel());
  434.              if (spell.getSchool().compareTo("Abjuration") == 0) {
  435.                 schoolComboBox.setSelectedIndex(0);
  436.                 }
  437.         else if (spell.getSchool().compareTo("Alteration") == 0) {
  438.             schoolComboBox.setSelectedIndex(1);
  439.             }
  440.         else if (spell.getSchool().compareTo("Conjuration/Summoning") == 0) {
  441.             schoolComboBox.setSelectedIndex(2);
  442.             }
  443.         else if (spell.getSchool().compareTo("Enchantment/Charm") == 0) {
  444.             schoolComboBox.setSelectedIndex(3);
  445.             }
  446.         else if (spell.getSchool().compareTo("Illusion/Phantasm") == 0) {
  447.             schoolComboBox.setSelectedIndex(4);
  448.             }
  449.         else if (spell.getSchool().compareTo("Invocation") == 0 ||
  450.                  spell.getSchool().compareTo("Evocation") == 0) {
  451.             schoolComboBox.setSelectedIndex(5);
  452.             }
  453.         else if (spell.getSchool().compareTo("Divination") == 0) {
  454.             schoolComboBox.setSelectedIndex(6);
  455.             }
  456.         else if (spell.getSchool().compareTo("Necromancy") == 0) {
  457.             schoolComboBox.setSelectedIndex(7);
  458.             }
  459.         else if (spell.getSchool().compareTo("Wild Magic") == 0) {
  460.             schoolComboBox.setSelectedIndex(8);
  461.             }
  462.         componentsComboBox.setSelectedIndex(spell.getComponents() - 1);
  463.         rangeTextField.setText(spell.getRange());
  464.         durationTextField.setText(spell.getDuration());
  465.         castingTimeTextField.setText(spell.getCastingTime());
  466.         areaOfEffectTextField.setText(spell.getAreaOfEffect());
  467.         savingThrowTextField.setText(spell.getSavingThrow());
  468.         descriptionTextArea.setText(spell.getEffect().getDescription());
  469.         }
  470.     
  471.     }
  472.